/**
 * Copyright (C) 2010 altuure <altuure [AT] gmail [DOT] com> http://www.altuure.com/projects/yagdao
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.altuure.yagdao.blog.dao;

import com.altuure.yagdao.*;
import com.altuure.yagdao.blog.model.User;

import java.util.HashSet;
import java.util.Set;

public interface UserDAO extends GenericDAO<User,Long>{

    @YMethod(type = YMethodType.SAVE)
    User create(
            @YParameter("username")String username,
            @YParameter("password")String password,
            @YParameter("email")String email);

    @YMethod(type = YMethodType.UPDATE)
    User updateRoles(long id, @YParameter("roles")Set roles);

    @YMethod(type = YMethodType.UPDATE)
    User updatePassword(long id, @YParameter("password")String password);
    
    @YMethod(type = YMethodType.EXECUTE,query="update User set password=:password")
    int updateAllPasswords(String newPassword);
    
    @YMethod(type = YMethodType.CRITERIA)
    @YFetch("roles")
    User findByUsername(@YParameter(value = "username")String username);

    @YMethod(type = YMethodType.APPEND)
    @YFetch("roles")
    User findByUsername2(@YParameter(value = "username = ? ")String username);

    @YMethod(type = YMethodType.QUERY, query="select u.username from User u where u.email=:email")
    String findUsernameByEmailQuery(@YParameter(value = "email")String email);

    @YMethod(type = YMethodType.QUERY, queryName="findByEmail")
    String findUsernameByEmailNamed(@YParameter(value = "email")String email);    

    @YMethod(type = YMethodType.APPEND, select="username")
    String findUsernameByEmailAppend(@YParameter(value = "email=?")String email);    
    
    @YMethod(type = YMethodType.CRITERIA, select="username")
    String findUsernameByEmailCriteria(@YParameter(value = "email")String email);   
    
    @YMethod(type = YMethodType.CRITERIA)
    SearchResultList listUsers(YPage page);

}
